//
//  WCOrderListCell.m
//  CBT
//
//  Created by apple on 2019/7/8.
//  Copyright © 2019 Mr.Zhang. All rights reserved.
//

#import "WCOrderListCell.h"
#import "WCOrderCompletedModel.h"

@implementation WCOrderListCell

+ (instancetype)createTableView:(UITableView *)tableView {
    WCOrderListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"orderlistCell"];
    cell.selectionStyle   = UITableViewCellSelectionStyleNone;
    cell.backgroundColor  = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];

    [cell makeViews];
    
    return cell;
}

- (void)makeViews {
    
    CGFloat width = (SCREEN_WIDTH-30);
    
    UIView *bgview = [[UIView alloc] init];
    bgview.layer.cornerRadius = 5;
    bgview.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgview];
    [bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(8);
        make.height.mas_equalTo(174);
        make.width.mas_equalTo(width);
    }];
    
    [bgview addSubview:self.titleImg];
    [self.titleImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(40);
        make.width.height.mas_equalTo(90);
    }];
    
    [bgview addSubview:self.firstLabel];
    [self.firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(130);
        make.top.mas_equalTo(50);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(width-100);
    }];
    
    [bgview addSubview:self.secondLabel];
    [self.secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(130);
        make.top.mas_equalTo(50+29);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(width-100);
    }];
    [bgview addSubview:self.thirdLabel];
    [self.thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(130);
        make.top.mas_equalTo(50+29*2);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(width-100);
    }];
    [bgview addSubview:self.forthLabel];
    [self.forthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(130);
        make.top.mas_equalTo(50+29*3);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(width-100);
    }];
    [bgview addSubview:self.orderStatus];
    [self.orderStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-23);
        make.top.mas_equalTo(23);
        make.height.mas_equalTo(13);
    }];
}

- (void)setModel:(WCOrderCompletedModel *)model {
    _model = model;
    
    _firstLabel.text  = [NSString stringWithFormat:@"%@",model.name];
    _secondLabel.text = [NSString stringWithFormat:@"%@：%@", kLocalizedString(@"付款时间", nil),[NSString getShowDateMonthDayWithTime:[model.orderDate longLongValue]]];
    _thirdLabel.text  = [NSString stringWithFormat:@"%@：%@",kLocalizedString(@"订单号", nil),model.orderNum];
    _forthLabel.text  =  [NSString stringWithFormat:@"%@%@%@ %@%.4f%@",kLocalizedString(@"共计", nil),model.num,kLocalizedString(@"件商品", nil),kLocalizedString(@"总计", nil),[model.price floatValue],model.coinName];
    _orderStatus.text = [NSString stringWithFormat:@"%@",[self transformStatus:model.status]];
   
    [_titleImg lf_setImageURL:[NSString stringWithFormat:@"%@/%@",kBaseURL_PICSTATIC,model.img]];
}

- (NSString *)transformStatus:(NSNumber *)status {
    switch ([status integerValue]) {
        case 0:
            return kLocalizedString(@"已付款", nil);
        case 1:
            return kLocalizedString(@"待收货", nil);
        case 2:
            return kLocalizedString(@"已完成", nil);
        default:
            return kLocalizedString(@"已付款", nil);
    }
}

- (UILabel *)firstLabel {
    if (!_firstLabel) {
        _firstLabel = [[UILabel alloc] init];
        _firstLabel.textColor = UIColorFromRGB(0x404040);
        _firstLabel.font = [UIFont systemFontOfSize:13];
        _firstLabel.text = @"--";
    }
    
    return _firstLabel;
}

- (UILabel *)secondLabel {
    if (!_secondLabel) {
        _secondLabel = [[UILabel alloc] init];
        _secondLabel.textColor = UIColorFromRGB(0x404040);
        _secondLabel.font = [UIFont systemFontOfSize:13];
        _secondLabel.text = @"付款时间:--";
    }
    
    return _secondLabel;
}

- (UILabel *)thirdLabel {
    if (!_thirdLabel) {
        _thirdLabel = [[UILabel alloc] init];
        _thirdLabel.textColor = UIColorFromRGB(0x404040);
        _thirdLabel.font = [UIFont systemFontOfSize:13];
        _thirdLabel.text = @"订单号：--";
    }
    
    return _thirdLabel;
}

- (UILabel *)forthLabel {
    if (!_forthLabel) {
        _forthLabel = [[UILabel alloc] init];
        _forthLabel.textColor = UIColorFromRGB(0x404040);
        _forthLabel.font = [UIFont systemFontOfSize:13];
        _forthLabel.text = @"共-件商品 合计--AKB";
    }
    
    return _forthLabel;
}

- (UILabel *)orderStatus {
    if (!_orderStatus) {
        _orderStatus = [[UILabel alloc] init];
        _orderStatus.textColor = UIColorFromRGB(0x7F64FC);
        _orderStatus.font = [UIFont systemFontOfSize:13];
        _orderStatus.text = @"已付款";
    }
    
    return _orderStatus;
}

- (UIImageView *)titleImg {
    if (!_titleImg) {
        _titleImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"default_watch"]];
        _titleImg.layer.cornerRadius  = 45;
        _titleImg.layer.masksToBounds = YES;
    }
    
    return _titleImg;
}


@end
